package com.example.demo.service.impl;

import com.example.demo.dao.MenuDao;
import com.example.demo.pojo.Menu;
import com.example.demo.service.MenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 翁佃峰
 * date:2020/10/29 12:55
 */
@Service
public class MenuServiceImpl implements MenuService {
    @Resource
    MenuDao menuDao;

    @Override
    public List<Menu> getMenuList() {
        List<Menu> lowestMenu = menuDao.getTopMenu();
        setLostMenuByMenu(lowestMenu);
        return lowestMenu;
    }

    @Override
    public List<Menu> setLostMenuByMenu(List<Menu> menuList) {

        for (Menu menu : menuList) {
            List<Menu> menuList1 = menuDao.getMenuList(menu.getId());
            setLostMenuByMenu(menuList1);
            menu.setSubMenu(menuList1);
        }
        return menuList;
    }
}
